package com.example.administrator.myapplication;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Main3Activity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private RadioGroup RadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        initView();
        initData();
        initEvent();
    }

    private void initView() {


        RadioGroup = (RadioGroup) findViewById(R.id.radiogroup);

    }

    private void initData() {

    }

    private void initEvent() {
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                Toast.makeText(Main3Activity.this,checkedId+ "", Toast.LENGTH_SHORT).show();
            //if(checkedId == 4){高版本使用
if(checkedId == R.id.radioBtn1){
    Toast.makeText(Main3Activity.this, "您选择了女生", Toast.LENGTH_SHORT).show();
}else{
    Toast.makeText(Main3Activity.this, "您选择了男生", Toast.LENGTH_SHORT).show();
}

            }
        });
    }


}
